﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

namespace SONORA2012
{
	public partial class Test : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

		protected void Button1_Click(object sender, EventArgs e)
		{
			string MSG = null;

			XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "true"), new XElement("databox", new XElement("construct"), new XElement("queries"), new XElement("queryresults"), new XElement("messages")));

			// messages elementinin içine gelecek olan message elementleri 2 tane attribute alacak;
			// ilki mesajın kendisi olacak, ikincisi ise mesajın türü (INFO, WARNING, ERROR)

			#region Eski XML Databox Yapısı
			//XElement newTableElement = new XElement("query",
			//                                            new XAttribute("name", "DEF_YESNO"),
			//                                            new XAttribute("description", ""),
			//                                            new XElement("command",
			//                                                new XAttribute("name", "SELECT")
			//                                            ),
			//                                            new XElement("columns",
			//                                                new XElement("column", new XAttribute("name", "ID")),
			//                                                new XElement("column", new XAttribute("name", "DESCRIPTION")),
			//                                                new XElement("column", new XAttribute("name", "DBVERSION")),
			//                                                new XElement("column", new XAttribute("name", "CREATEDBY")),
			//                                                new XElement("column", new XAttribute("name", "CREATEDTIME")),
			//                                                new XElement("column", new XAttribute("name", "UPDATEDBY")),
			//                                                new XElement("column", new XAttribute("name", "UPDATEDTIME"))
			//                                            ),
			//                                            new XElement("values",
			//                                                new XElement("value", new XAttribute("name", "SEQ_DEF_YESNO.nextval")),
			//                                                new XElement("value", new XAttribute("name", "'NO'")),
			//                                                new XElement("value", new XAttribute("name", "1")),
			//                                                new XElement("value", new XAttribute("name", "0")),
			//                                                new XElement("value", new XAttribute("name", "SYSDATE")),
			//                                                new XElement("value", new XAttribute("name", "0")),
			//                                                new XElement("value", new XAttribute("name", "SYSDATE"))
			//                                            ),
			//                                            new XElement("wheres",
			//                                                new XElement("where", new XAttribute("name", "ID=1"))
			//                                            ),
			//                                            new XElement("orders",
			//                                                new XElement("order", new XAttribute("name", "ID"))
			//                                            )
			//                                        );
			#endregion

			XElement newTableElement = new XElement("query", new XAttribute("name", "SELECT DEF_YESNO.ID,DEF_YESNO.DESCRIPTION FROM DEF_YESNO ORDER BY DEF_YESNO.ID"));
			doc.Element("databox").Elements("queries").Single().Add(newTableElement);

			SNRDB.SNRTable newSNRTable = new SNRDB.SNRTable("DEF_YESNO");
			newSNRTable.Select(ref doc);
			doc.Save(HttpContext.Current.Server.MapPath("~/DataBox.xml"));

			#region Eski List Yapısı
			//List<string> ColumnList = new List<string>();
			//List<string> ValueList = new List<string>();
			//List<string> WhereList = new List<string>();
			//List<string> OrderList = new List<string>();
			//ColumnList.Add("ID");
			//ColumnList.Add("DESCRIPTION");
			//ColumnList.Add("DBVERSION");
			//ColumnList.Add("CREATEDBY");
			//ColumnList.Add("CREATEDTIME");
			//ColumnList.Add("UPDATEDBY");
			//ColumnList.Add("UPDATEDTIME");
			//ValueList.Add("SEQ_DEF_YESNO.nextval");
			//ValueList.Add("'NO'");
			//ValueList.Add("1");
			//ValueList.Add("0");
			//ValueList.Add("SYSDATE");
			//ValueList.Add("0");
			//ValueList.Add("SYSDATE");
			//newSNRTable.Select(ColumnList, WhereList, OrderList);
			//newSNRTable.Insert(ColumnList, ValueList, out MSG);
			//newSNRTable.Update(ColumnList, WhereList);
			//newSNRTable.Delete(ColumnList, WhereList);
			#endregion
		}
	}
}